package com.topvision.controller.zwan;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.model.zwan.DeviceVendor;
import com.topvision.service.zwan.DeviceVendorService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;
import com.topvision.controller.AbstractController;

/**
 * 设备供应商
 *
 * @author shengwm
 * @email 179653076@qq.com
 * @date 2017-09-07 14:17:37
 */
@RestController
@RequestMapping("zwan/devicevendor")
public class DeviceVendorController extends AbstractController {
    @Autowired
    private DeviceVendorService deviceVendorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("zwan/devicevendor:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<DeviceVendor> deviceVendorList = deviceVendorService.queryList(query);
        int total = deviceVendorService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(deviceVendorList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("zwan/devicevendor:info")
    public R info(@PathVariable("id") Long id){
        DeviceVendor deviceVendor = deviceVendorService.queryObject(id);
        return R.success().put("deviceVendor", deviceVendor);
    }

    /**
     * 所有列表
     */
    @RequestMapping("/vendors")
    public R vendors(){
        Map<String,Object> map = new HashMap<>();
        List<DeviceVendor> vendors = deviceVendorService.queryByParam(map);
        return R.success().put("vendors", vendors);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("zwan/devicevendor:save")
    public R save(@RequestBody DeviceVendor deviceVendor){
		deviceVendorService.save(deviceVendor);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("zwan/devicevendor:update")
    public R update(@RequestBody DeviceVendor deviceVendor){
		deviceVendorService.update(deviceVendor);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("zwan/devicevendor:delete")
    public R delete(@RequestBody Long[] ids){
		deviceVendorService.deleteBatch(ids);
        return R.success();
    }

}
